package com.liangzhong.proxy.talent
{
	import com.liangzhong.commandconst.commandType.MainCommandType;
	import com.liangzhong.commandconst.talent.SMDTalent;
	import com.liangzhong.constants.HttpRequestConst;
	import com.liangzhong.errortip.ErrorTips;
	import com.liangzhong.global.CMD_Head;
	import com.liangzhong.proxy.BaseProxy;
	import com.liangzhong.proxy.ProxyUtils;
	import com.socket.clientsocket.IClientSocket;
	
	import flash.net.URLVariables;
	import flash.utils.ByteArray;
	
	import lz.controls.Alert;

	/**
	 *天赋 
	 * @author Administrator
	 * 
	 */	
	public class TalentProxy extends BaseProxy
	{
		
		/**
		 *俱乐部proxy名字 
		 */
		public static const PROXYNAME:String = "TalentProxy";
		public function TalentProxy(proxyName:String=PROXYNAME, data:Object=null)
		{
			super(proxyName, data);
		}
		/**
		 *接受 
		 * @param mainCmdID
		 * @param subCmdID
		 * @param buffer
		 * @param dataSize
		 * @param clientSocket
		 * @return 
		 * 
		 */		
		override public function onSocketRead(mainCmdID:uint, subCmdID:uint, buffer:ByteArray, dataSize:int, clientSocket:IClientSocket):Boolean
		{
			switch(mainCmdID)
			{
				case MainCommandType.MAINDEAL:
					return onDeal(subCmdID,buffer,dataSize,clientSocket);
					
			}
			return false;
		}
		
		private function onDeal(subCmdID:uint, buffer:ByteArray, dataSize:int, clientSocket:IClientSocket):Boolean
		{
			switch(subCmdID)
			{
				case SMDTalent.RESETTALENT:
					getResetTalent(buffer);
					return true;
				case SMDTalent.ACTIVATETALENT:
					getactivateTalent(buffer);
					return true;
					
			}
			return false;
		}
		
		/**
		 *请求天赋信息 
		 * 
		 */
		public function requestTalentInfo():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.TALENT_INFO;
			ProxyUtils.instance.webClient(getTalentInfo,variables,false);
		}
		
		/**
		 *返回天赋信息 
		 * @param $data
		 * 
		 */
		private function getTalentInfo($data:Object):void
		{
			var obj:Object = ProxyUtils.instance.analysisHttpData($data,TalentProxy);
			if(obj.retcode == 0)
			{
//				this.sendNotification(ActivityConst.GET_ONLINE_INFO);
			}
		}
		/**
		 *重置天赋 
		 * 
		 */
		public function requestResetTalent($obj:Object):void
		{
			var sendBuf :ByteArray = 
				CMD_Head.getHeadByteArrayBuff(CMD_Head.Size + 2,MainCommandType.MAINDEAL,SMDTalent.RESETTALENT);
			sendBuf.position = 0;
			clientSocket.sendData(sendBuf,sendBuf.bytesAvailable);
		}
		/**
		 *返回天赋 
		 * @param buffer
		 * 
		 */
		private function getResetTalent(buffer:ByteArray):void
		{
			var nReturn:int = buffer.readInt();
			if(nReturn ==0)
			{
				
			}else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(nReturn));
			}
		}
		
		/**
		 * 激活天赋 
		 * 
		 */
		public function requestactivateTalent($obj:Object):void
		{
			var sendBuf :ByteArray = 
				CMD_Head.getHeadByteArrayBuff(CMD_Head.Size + 2,MainCommandType.MAINDEAL,SMDTalent.ACTIVATETALENT);
			sendBuf.position = 0;
			clientSocket.sendData(sendBuf,sendBuf.bytesAvailable);
		}
		/**
		 *返回激活天赋 
		 * @param buffer
		 * 
		 */
		private function getactivateTalent(buffer:ByteArray):void
		{
			var nReturn:int = buffer.readInt();
			if(nReturn ==0)
			{
				
			}else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(nReturn));
			}
		}
		
	}
}